package com.study.spark.dao.task;

import java.sql.ResultSet;

import com.study.spark.domain.task.Task;
import com.study.spark.jdbc.JDBCHelper;

/**
 * 任务管理DAO实现类
 * 
 * @author Administrator
 *
 */
public class TaskDaoImpl implements TaskDao {

  /**
   * 根据主键查询任务
   * 
   * @param taskid
   *          主键
   * @return 任务
   */
  public Task findById(long taskid) {
    final Task task = new Task();

    String sql = "select * from task where task_id=?";
    Object[] params = new Object[] {
        taskid };

    JDBCHelper.getInstance().executeQuery(sql, params, new JDBCHelper.QueryCallback() {

      @Override
      public void process(ResultSet rs) throws Exception {
        if (rs.next()) {
          task.setTaskid(rs.getLong(1));
          task.setTaskName(rs.getString(2));
          task.setCreateTime(rs.getString(3));
          task.setStartTime(rs.getString(4));
          task.setFinishTime(rs.getString(5));
          task.setTaskType(rs.getString(6));
          task.setTaskStatus(rs.getString(7));
          task.setTaskParam(rs.getString(8));
        }
      }

    });

    return task;
  }

}
